package com.ruoyi.experiment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.experiment.domain.ExperimentsType;
import com.ruoyi.experiment.service.IExperimentsTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实验类型管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-18
 */
@RestController
@RequestMapping("/experiment/experimentType")
public class ExperimentsTypeController extends BaseController
{
    @Autowired
    private IExperimentsTypeService experimentsTypeService;

    /**
     * 查询实验类型管理列表
     */
     //@preAuthorize("@ss.hasPermi('experiment:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExperimentsType experimentsType)
    {
        startPage();
        List<ExperimentsType> list = experimentsTypeService.selectExperimentsTypeList(experimentsType);
        return getDataTable(list);
    }

     //@preAuthorize("@ss.hasPermi('experiment:type:list')")
    @GetMapping("/listall")
    public TableDataInfo listAll(ExperimentsType experimentsType)
    {
        List<ExperimentsType> list = experimentsTypeService.selectExperimentsTypeList(experimentsType);
        return getDataTable(list);
    }

    /**
     * 导出实验类型管理列表
     */
     //@preAuthorize("@ss.hasPermi('experiment:type:export')")
    @Log(title = "实验类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExperimentsType experimentsType)
    {
        List<ExperimentsType> list = experimentsTypeService.selectExperimentsTypeList(experimentsType);
        ExcelUtil<ExperimentsType> util = new ExcelUtil<ExperimentsType>(ExperimentsType.class);
        util.exportExcel(response, list, "实验类型管理数据");
    }

    /**
     * 获取实验类型管理详细信息
     */
     //@preAuthorize("@ss.hasPermi('experiment:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(experimentsTypeService.selectExperimentsTypeByTypeId(typeId));
    }

    /**
     * 新增实验类型管理
     */
     //@preAuthorize("@ss.hasPermi('experiment:type:add')")
    @Log(title = "实验类型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExperimentsType experimentsType)
    {
        return toAjax(experimentsTypeService.insertExperimentsType(experimentsType));
    }

    /**
     * 修改实验类型管理
     */
     //@preAuthorize("@ss.hasPermi('experiment:type:edit')")
    @Log(title = "实验类型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExperimentsType experimentsType)
    {
        return toAjax(experimentsTypeService.updateExperimentsType(experimentsType));
    }

    /**
     * 删除实验类型管理
     */
     //@preAuthorize("@ss.hasPermi('experiment:type:remove')")
    @Log(title = "实验类型管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(experimentsTypeService.deleteExperimentsTypeByTypeIds(typeIds));
    }
}
